package ru.nsu.ccfit.shumkina.algorithm.graphworks;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Вера
 * Time: 22:11
 * To change this template use File | Settings | File Templates.
 */
public class DotGraphSaver {
    public static void saveGraphToDot(Graph graph, String fileName)
    {
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
            bw.write("digraph graphname {");
            bw.newLine();

            for (Map.Entry<String, Page> entry: graph.pages.entrySet())
            {
                bw.write("\t" + entry.getKey() + ";");
                bw.newLine();
            }
            bw.newLine();
            for (Map.Entry<String, String> entry: graph.arcNames.entrySet())
            {
                bw.write("\t" + entry.getKey() + ";");
                bw.newLine();
            }

            bw.write("}");
            bw.newLine();
            bw.close();

        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
